<template>
  <div class="wrapper">
    <div class="nav">
      <input class="input"   v-model="text">
      <div class="creat" @click="create">+</div>
    </div>
    <router-link v-for="(item, index) in Data" class="content" :key="index" :to="{
      name:'Detail-information',
      params:{
        Id:item.objectId,
      }

    }">
      {{item.content}}
    </router-link>
  </div>
</template>
<script>

import axios from 'axios'

export default {
  name: "Home",
  data() {
    return {
      text: '',
      Data: []
    }
  },
  created() {
    this.getTodoList();
  },
  methods: {
    getTodoList() {
      axios.get("https://api.yizhanketang.cn/api/v1/todos").then(res => {
        const {data: Data} = res.data;
        this.Data = Data;
        console.log(this.Data)
      })
    },
    create(){
      axios.post("https://api.yizhanketang.cn/api/v1/todos",{content:this.text}).then(()=>{
      this.getTodoList()

      })//注意这里是post 请求不需要去获取回应的结果，所以参数为空

}

  }
}
</script>
<style lang="scss">
  a{
    display: block;
  }
  .nav{
    height: 20px;
    width: 200px;
    display: flex;
    margin: 0 auto;
    .creat{
      height: 20px;
      width: 20px;
      border: 1px solid #42b983;
      box-sizing: border-box;

    }
    .input{
      border: 1px solid #42b983;
    }
  }
  .content{
    height: 40px;
    width: 200px;
    border: 1px solid #42b983;
    margin: 20px auto;

  }

</style>
